package cn.tedu._05weibo.controller;

import cn.tedu._05weibo.mapper.CommentMapper;
import cn.tedu._05weibo.pojo.dto.CommentDTO;
import cn.tedu._05weibo.pojo.entity.Comment;
import cn.tedu._05weibo.pojo.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/v1/comment/")
public class CommentController {

    @Autowired
    public CommentMapper commentMapper;
    @PostMapping("insert")
    public int insertComment(CommentDTO commentDTO , HttpSession session){

        /**
         * 1.接受数据
         * 2.检查用户状态，登录状态
         *      2.1 未登录，提示登录
         *      2.2 已登录，执行业务
         */
        UserVO user = (UserVO) session.getAttribute("user");
        if(user==null){
            return 2;
        }
        Comment comment = new Comment();
        BeanUtils.copyProperties(commentDTO,comment);

        commentMapper.insertComment(comment);

        return 1;
    }





}
